package com.strawcom.charmring.ui;

import java.util.ArrayList;

import com.strawcom.charmring.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AdviceListAdapter extends BaseAdapter {

	//private int[] adviceList;
	private ArrayList<String> list;
	private Context context;
	private int itemid;
	
	public AdviceListAdapter(Context context, int itemid, ArrayList<String> list){
		this.context = context;
		this.itemid = itemid;
		this.list = list;
		System.out.println("list's size is " + list.size());
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String text = list.get(position);
		ViewCache viewCache;
		if(convertView == null){
			viewCache = new ViewCache();
			convertView = LayoutInflater.from(context).inflate(itemid, null);
			viewCache.iv = (ImageView) convertView.findViewById(R.id.img_chk);
			viewCache.tv = (TextView) convertView.findViewById(R.id.advice_text);
			viewCache.tv.setText(text);
			
			convertView.setTag(viewCache);
		}else {
            viewCache = (ViewCache) convertView.getTag();
        }
		
		return convertView;
	}

	class ViewCache{
		ImageView iv;
		TextView tv;
	}
}
